<template>
  <lb-layout
    v-loading="$store.getters.loading"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="#a19f9fb0;"
    :paddBottom="5"
  >
    <el-table
      v-loading="loading"
      :data="list.slice((pageNum - 1) * pageSize, pageNum * pageSize)"
      style="width: 100%"
      border
    >
      <el-table-column
        label="目标名称"
        align="center"
        prop="repo"
        :show-overflow-tooltip="true"
      >
      </el-table-column>

      <el-table-column
        label="编译主机"
        align="center"
        prop="git.build.host"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span>{{ scope.row["git.build.host"] }}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="编译时间"
        align="center"
        prop="git.build.time"
        width="200"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span>{{ scope.row["git.build.time"] }}</span>
        </template>
      </el-table-column>

      <el-table-column label="分支" align="center" prop="git.branch">
        <template slot-scope="scope">
          <span>{{ scope.row["git.branch"] }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="提交编号"
        align="center"
        prop="git.commit.id.abbrev"
      >
        <template slot-scope="scope">
          <span>{{ scope.row["git.commit.id.abbrev"] }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="提交时间"
        align="center"
        prop="git.commit.time"
        width="200"
      >
        <template slot-scope="scope">
          <span>{{ scope.row["git.commit.time"] }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="small"
            type="text"
            icon="el-icon-view"
            @click="handleDetail(scope.row)"
            >详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="pageNum"
      :limit.sync="pageSize"
    />
    <detail :visible.sync="show" :rowsData="row" @close="close"></detail>
  </lb-layout>
</template>

<script>
import { getBuildGitInfo } from "@/api/common";
import detail from "@/views/maintenance/monitor/gitLog/components/detail";
const GitRevisionPlugin = require("git-revision-webpack-plugin");
const gitRevision = new GitRevisionPlugin();
export default {
  name: "GitLog",
  components: {
    detail,
  },
  data() {
    return {
      row: {},
      show: false,
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      pageNum: 1,
      pageSize: 10,
      // 查询参数
      queryParams: {
        ipaddr: undefined,
        userName: undefined,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询登录日志列表 */
    getList() {
      this.loading = true;
      getBuildGitInfo(this.queryParams).then((response) => {
        this.loading = false;
        this.list = [
          {
            repo: "skst-ui",
            "git.commit.id": process.env.VUE_APP_COMMITHASH,
            "git.commit.id.abbrev": process.env.VUE_APP_VERSION,
            "git.branch": process.env.VUE_APP_BRANCH,
            "git.commit.time": process.env.VUE_APP_BUILD_DATE,
          },
        ];
        response.data.repo = "skst-admin";
        this.list.push(response.data);
      });
    },
    close() {
      this.show = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 详情操作 */
    handleDetail(params) {
      this.row = params;
      this.show = true;
    },
  },
};
</script>
